package com.csair.platform.cit.service.controller;

import java.util.List;

import com.csair.platform.cit.service.core.CheckDataPermission;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.csair.invoice.common.base.vo.JsonResult;
import com.csair.platform.cit.facade.A202000Api;
import com.csair.platform.cit.facade.model.CitQueryParam;
import com.csair.platform.cit.facade.model.a202000.CitFzjgFormVo;
import com.csair.platform.cit.facade.model.a202000.CitFzjgSaveVo;
import com.csair.platform.cit.facade.model.a202000.CitZjgxxFormVo;
import com.csair.platform.cit.service.biz.IA202000Service;
import com.csair.platform.cit.service.core.CheckAnyPermission;
import com.csair.platform.cit.service.entity.CitFzjg;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;

/**
 * 企业所得税分配表数据接口
 * @author caoyu
 *
 */
@Api(tags = "企业所得税分配表数据")
@Slf4j
@RestController
public class A202000Controller extends BaseController implements A202000Api {

    /**
     * [分配表数据]服务
     */
    @Autowired
    IA202000Service a202000Service;
    
    /**
     * 保存分配表数据
     */
	@CheckAnyPermission(values={"qysds", "citReport"})
	@CheckDataPermission
    @ApiOperation(value = "保存分配表数据")
	@Override
	public JsonResult<Void> saveData(@RequestBody CitFzjgSaveVo fzjgSaveVo) {
    	log.info("保存[分配表数据]，请求参数:{}", JSON.toJSONString(fzjgSaveVo));
    	CitZjgxxFormVo zjgxxFormVo = fzjgSaveVo.getZjgxx();
    	List<CitFzjgFormVo> fzjgxxFormVo = fzjgSaveVo.getFzjgxx();
    	a202000Service.saveData(zjgxxFormVo, fzjgxxFormVo);
    	return JsonResult.success();
	}

    /**
     * 获取分配表数据
     */
	@CheckAnyPermission(values={"qysds", "citReport"})
	@CheckDataPermission
    @ApiOperation(value = "获取分配表数据")
	@Override
	public JsonResult<JSONObject> query(@Validated @RequestBody CitQueryParam param) {
		log.info("获取[分配表数据]，请求参数:{}", JSON.toJSONString(param));
		return a202000Service.query(param, getCurrentUser(), false);
	}

    /**
     * 获取分支机构数据
     */
	@CheckAnyPermission(values={"qysds", "citReport"})
	@CheckDataPermission
    @ApiOperation(value = "获取分支机构数据")
	@Override
	public JsonResult<JSONObject> queryFzjg(@PathVariable String year) {
		log.info("获取[分支机构数据]，请求参数:{}", JSON.toJSONString(year));
		List<CitFzjg> list = a202000Service.queryFzjg(Integer.parseInt(year));
		JSONObject result = new JSONObject();
		result.put("fzjgxx", list);
		return JsonResult.success(result);
	}
}
